package com.prime.tutorial.moviestore.service.testconfiguration;

import com.prime.tutorial.moviestore.Constants;
import com.prime.tutorial.moviestore.dao.*;
import com.prime.tutorial.moviestore.domain.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * Users: me
 * Date: 21 лют 2010
 * Time: 14:45:38
 */

@Service
public class TestConfigurationServiceImpl implements TestConfigurationService {
    GroupsDAO groupsDAO;
    UserDAO userDAO;
    StateDAO stateDAO;
    ModelTypeDAO modelTypeDAO;
    ModelDAO modelDAO;
    DeviceDAO deviceDAO;
    PortTypeDAO portTypeDAO;


    @Autowired
    public TestConfigurationServiceImpl(GroupsDAO groupsDAO,
                                        UserDAO userDAO,
                                        StateDAO stateDAO,
                                        ModelTypeDAO modelTypeDAO,
                                        ModelDAO modelDAO,
                                        DeviceDAO deviceDAO,
                                        PortTypeDAO portTypeDAO) {
        this.groupsDAO = groupsDAO;
        this.userDAO = userDAO;
        this.stateDAO = stateDAO;
        this.modelTypeDAO = modelTypeDAO;
        this.modelDAO = modelDAO;
        this.deviceDAO=deviceDAO;
        this.portTypeDAO = portTypeDAO;

    }

    public void createGroups(){
         Groups g1 = new Groups(Constants.GROUP_ADMIN_NAME);
         groupsDAO.persist(g1);

         Groups g2 = new Groups(Constants.GROUP_NETWPLANNING_NAME);
         groupsDAO.persist(g2);

         Groups g3 = new Groups(Constants.GROUP_LOGISTICS_NAME);
         groupsDAO.persist(g3);

         Groups g4 = new Groups(Constants.GROUP_TECHSUPPORT_NAME);
         groupsDAO.persist(g4);

         Groups g5 = new Groups(Constants.GROUP_REPORTS_NAME);
         groupsDAO.persist(g5);
    };

    public void createAdmin(){
        
        Users admin = new Users((groupsDAO.findByName(Constants.GROUP_ADMIN_NAME).get(0)),
                              "admin",
                              "admin",
                              "admin",
                              "testPass",
                              true,
                              "Test Admin",
                              new Date(),
                              new Date());
        userDAO.persist(admin);
    };

    public void createDeviceStates(){
        stateDAO.persist(new State(Constants.STATE_ENABLED));
        stateDAO.persist(new State(Constants.STATE_WITH_ERRORS));
        stateDAO.persist(new State(Constants.STATE_ON_STORAGE));
        stateDAO.persist(new State(Constants.STATE_PLANNED_INSTALLATION));
        stateDAO.persist(new State(Constants.STATE_AVAILABLE_INSTALLATION));
        stateDAO.persist(new State(Constants.STATE_PLANNED_REMOVAL));
        stateDAO.persist(new State(Constants.STATE_APPROVED_INSTALLATION));
    }

    public void createModelTypes(){
        modelTypeDAO.persist(new ModelType(Constants.MODELTYPE_CPE));
        modelTypeDAO.persist(new ModelType(Constants.MODELTYPE_LRESWITCH));
        modelTypeDAO.persist(new ModelType(Constants.MODELTYPE_ROUTER));
        modelTypeDAO.persist(new ModelType(Constants.MODELTYPE_SPLITTER));
        modelTypeDAO.persist(new ModelType(Constants.MODELTYPE_SWITCH));
    }

    public void createModels(){
       //switches
       modelDAO.persist(new Model(Constants.MODEL_SWITCH_CiscoCatalyst2560V224TS,
                                  modelTypeDAO.findByType(Constants.MODELTYPE_SWITCH).get(0)));
       modelDAO.persist(new Model(Constants.MODEL_SWITCH_CiscoCatalyst2560V248TS,
                                  modelTypeDAO.findByType(Constants.MODELTYPE_SWITCH).get(0)));

       //routers
       modelDAO.persist(new Model(Constants.MODEL_ROUTER_CISCO2951,
                                  modelTypeDAO.findByType(Constants.MODELTYPE_ROUTER).get(0)));
       modelDAO.persist(new Model(Constants.MODEL_ROUTER_CISCO3945,
                                  modelTypeDAO.findByType(Constants.MODELTYPE_ROUTER).get(0)));

        //lre switches
       modelDAO.persist(new Model(Constants.MODEL_LRESWITCH_CiscoCatalyst2912LREXL,
                                  modelTypeDAO.findByType(Constants.MODELTYPE_LRESWITCH).get(0)));
       modelDAO.persist(new Model(Constants.MODEL_LRESWITCH_CiscoCatalyst2924LREXL,
                                  modelTypeDAO.findByType(Constants.MODELTYPE_LRESWITCH).get(0)));

       //cpes
       modelDAO.persist(new Model(Constants.MODEL_CPE_Cisco575LRECPE,
                                  modelTypeDAO.findByType(Constants.MODELTYPE_CPE).get(0)));

       //splitters
       modelDAO.persist(new Model(Constants.MODEL_SPLITTER_CiscoLRE48,
                                  modelTypeDAO.findByType(Constants.MODELTYPE_SPLITTER).get(0)));
    };

    public void createDevices(){
        //some router with enabled state in kiev
        deviceDAO.persist(new Device(new Location(new Country("Ukraine"),
                                                  new City("Kiev"),
                                                  new Street("Yaroslaviv Val"),
                                                  new Building("5",0.0,0.0),
                                                  new Apartment("130")),
                                     stateDAO.findByType(Constants.STATE_ENABLED).get(0),
                                     modelDAO.findByType(Constants.MODEL_ROUTER_CISCO2951).get(0),
                                     "TestDevice1",
                                     "TestDevice1"));

                 deviceDAO.persist(new Device(new Location(new Country("Ukraine"),
                                                  new City("Kiev"),
                                                  new Street("Ny*nij Val"),
                                                  new Building("5",0.0,0.0),
                                                  new Apartment("120")),
                                     stateDAO.findByType(Constants.STATE_AVAILABLE_INSTALLATION).get(0),
                                     modelDAO.findByType(Constants.MODEL_ROUTER_CISCO2951).get(0),
                                     "TestDevice3",
                                     "TestDevice3"));

              deviceDAO.persist(new Device(new Location(new Country("Ukraine"),
                                                  new City("Kiev"),
                                                  new Street("Verhnij Val"),
                                                  new Building("5",0.0,0.0),
                                                  new Apartment("130")),
                                     stateDAO.findByType(Constants.STATE_AVAILABLE_INSTALLATION).get(0),
                                     modelDAO.findByType(Constants.MODEL_ROUTER_CISCO2951).get(0),
                                     "TestDevice4",
                                     "TestDevice4"));

              deviceDAO.persist(new Device(new Location(new Country("Ukraine"),
                                                  new City("Kiev"),
                                                  new Street("Puwkins'ka"),
                                                  new Building("5",0.0,0.0),
                                                  new Apartment("120")),
                                     stateDAO.findByType(Constants.STATE_APPROVED_INSTALLATION).get(0),
                                     modelDAO.findByType(Constants.MODEL_ROUTER_CISCO2951).get(0),
                                     "TestDevice5",
                                     "TestDevice5"));

              deviceDAO.persist(new Device(new Location(new Country("Ukraine"),
                                                  new City("Kiev"),
                                                  new Street("Puwkins'ka"),
                                                  new Building("5",0.0,0.0),
                                                  new Apartment("130")),
                                     stateDAO.findByType(Constants.STATE_APPROVED_INSTALLATION).get(0),
                                     modelDAO.findByType(Constants.MODEL_ROUTER_CISCO2951).get(0),
                                     "TestDevice6",
                                     "TestDevice6"));
              deviceDAO.persist(new Device(new Location(new Country("Ukraine"),
                                                  new City("Kiev"),
                                                  new Street("Nabere*no-Hrewatyc'ka"),
                                                  new Building("5",0.0,0.0),
                                                  new Apartment("120")),
                                     stateDAO.findByType(Constants.STATE_PLANNED_REMOVAL).get(0),
                                     modelDAO.findByType(Constants.MODEL_ROUTER_CISCO2951).get(0),
                                     "TestDevice7",
                                     "TestDevice7"));

              deviceDAO.persist(new Device(new Location(new Country("Ukraine"),
                                                  new City("Kiev"),
                                                  new Street("Nabere*no-Hrewatyc'ka"),
                                                  new Building("5",0.0,0.0),
                                                  new Apartment("130")),
                                     stateDAO.findByType(Constants.STATE_PLANNED_REMOVAL).get(0),
                                     modelDAO.findByType(Constants.MODEL_ROUTER_CISCO2951).get(0),
                                     "TestDevice8",
                                     "TestDevice8"));     
    }

    public void createPortTypes(){
        portTypeDAO.persist(new PortType(Constants.PORT_TYPE_ETHERNET));
        portTypeDAO.persist(new PortType(Constants.PORT_TYPE_SERIAL));
        portTypeDAO.persist(new PortType(Constants.PORT_TYPE_LRE));
        portTypeDAO.persist(new PortType(Constants.PORT_TYPE_RJ11));
    }

   

}
